import { UITemplate } from "../../mvc/ui_template";

export class HandCard extends UITemplate{
    card_type:number;
    width:number;
    face:number;

    constructor(parent){
        super();
        this.ui_package = "main";
        this.layout_name = "hand_card";
        this.parent = parent;
    }

    OpenViewCallback(...args: any[]){
        this.width = this.fairy_root.width;
        let on_open_callback = args[0];
        on_open_callback();
    }

    SetInfo(...args: any[]){
        let card_type = args[0];
        let birth_rect = args[1];
        let click_callback = args[2];
        this.face = 0;
        this.SetSelectedIndex("card_face", this.face);
        this.SetPosition(birth_rect.x, birth_rect.y);
        this.UpdateCardType(card_type);
        this.GetGButton("click_btn").onClick(()=>{
            click_callback()
        });
    }

    TurnCard(){
        if(this.face == 0){
            this.face = 1;
        }else{
            this.face = 0;
        }
        this.SetSelectedIndex("card_face", this.face);
    }

    Selected(is_select:boolean){
        if(is_select){
            this.SetScale(1.5, 1.5);
        }else{
            this.SetScale(1.0, 1.0);
        }
    }

    UpdateCardType(card_type:number){
        this.card_type = card_type;
        this.GetGText("name").text = config.card[this.card_type.toString()].name; 
    }

    Reset(){
        this.SetVisible(false);
        this.SetScale(1,1);
    }
}